/**
 * zmn文章模块-文章编辑
 * 文件命名格式：zmn.模块.表/功能.jas
 * @author duanzuocai
 * @since 2018/10/18
 */
layui.define(['form', 'layedit', 'laydate', 'upload'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    form.render(null, "zmn-form");

    // 自定义验证规则
    form.verify({
        ratio: function(value){
            if (! /^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/.test(value)) {
                return "只支持输入两位小数";
            }
            if (Number(value) > 2.0||Number(value) < 0.5) {
                return '数字范围必须在0.5和2.0之间';
            }
        }
    });

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var openId = layer.open({type: 3});
        var data = obj.field;
        var url = "/difficult/ratio/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(json) {
                layer.close(openId);
                if(json.status==200){
                    layer.msg(json.message,{time: 1000},()=>{
                        zmnLayUtil.closeThisIframe(parent,{reloadPage: true});
                        parent.window.document.forms[0].submit();
                    });
                }else{
                    layer.msg(json.message, {"icon": 2});
                }

            },
            error:function(XMLHttpRequest, textStatus, errorThrown){}
        })
        return false;
    });



    //对外暴露的接口
    exports('serv_difficultratio_edit', {});
});